﻿using FreeSql;
using ManaSky.DBCore.Entity;
using ManaSky.DBCore.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ManaSky.DBCore.IRepository
{
    /// <summary>
    /// 描述：公用仓储接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IFoundRepository<T> : IBaseRepository<T, int> where T : BaseEntity, new()
    {
        #region 单表操作
        /// <summary>
        /// ID获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task<T> GetByIdAsync(int id);
        /// <summary>
        /// 获取所有
        /// </summary>
        /// <returns></returns>
        public Task<IList<T>> GetListAsync();
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="select">连接查询</param>
        /// <param name="Page">分页条件</param>
        /// <returns></returns>
        public Task<PageListSearch<T>> GetPageListAsync(ISelect<T> select, PageModel Page);
        /// <summary>
        /// 主键删除(假)
        /// </summary>
        /// <param name="t">必须是带Stt列的数据类</param>
        /// <returns></returns>
        public Task<bool> FalseDelete(T t);
        /// <summary>
        /// 主键删除(真)
        /// </summary>
        /// <param name="t">数据</param>
        /// <returns></returns>
        public Task<bool> TrueDeleteAsync(T t);
        #endregion

        #region Sql和存储过程操作
        /// <summary>
        /// Sql查询
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        public Task<IList<T1>> SqlQueryAsync<T1>(string sql) where T1 : class;
        /// <summary>
        /// Sql查询(返回DataTable)
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        public Task<DataTable> SqlQueryDt<T1>(string sql) where T1 : class;
        /// <summary>
        /// Sql查询 分页
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="Page">分页</param>
        /// <returns></returns>
        public Task<PageListSearch<T1>> SqlQueryPage<T1>(string sql, PageModel Page) where T1 : class;
        /// <summary>
        /// Sql查询 分页(返回DataTable)
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="Page"></param>
        /// <returns></returns>
        public Task<PageListSearch<T1>> SqlQueryPageDt<T1>(string sql, PageModel Page) where T1 : class;
        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="name">存储过程名称</param>
        public void Procedure(string name);
        #endregion
    }
}
